﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace olierFrm.Log
{
    public static class Log4
    {
        private static log4net.ILog loginfo;
        private static log4net.ILog logerror;
        private static FileInfo logFile;

        public static void SetConfig()
        {
            if (logFile == null)
            {
                var filePath = AppDomain.CurrentDomain.BaseDirectory + "\\log4net.config";
                if (!System.IO.File.Exists(filePath))
                {
                    throw new Exception("日志组件配置错误，" + filePath + "，文件不存在。");
                }
                logFile = new FileInfo(filePath);
                SetConfig(logFile);
                loginfo = log4net.LogManager.GetLogger("loginfo");
                logerror = log4net.LogManager.GetLogger("logerror");
            }
        }

        public static void SetConfig(FileInfo configFile)
        {
            if (logFile == null)
            {
                logFile = configFile;
            }
            log4net.Config.XmlConfigurator.Configure(logFile);
        }

        public static log4net.ILog LogInfo { get { return loginfo; } }
        public static log4net.ILog LogError { get { return logerror; } }

    }
}
